// pages/my/my.js
const app = getApp()
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    headImg: '',
    phone: '',
    sex: '去登录',
    myList: [
      {
        icon: '/images/m_icon1.png',
        title: '账号信息',
        pathUrl: '/pages/account/account'
      },
      {
        icon: '/images/collect.png',
        title: '我的收藏',
        pathUrl: '/pages/collect/collect'
      },
      {
        icon: '/images/wz.png',
        title: '我的文章',
        pathUrl: '/pages/article/article'
      },
      {
        icon: '/images/m_icon2.png',
        title: '分享我的体验码',
        pathUrl: '/pages/tastecode/tastecode'
      },
      {
        icon: '/images/m_icon3.png',
        title: '设置查询密码',
        pathUrl: '/pages/set/set'
      },
      {
        icon: '/images/m_icon4.png',
        title: '充值次数',
        pathUrl: '/pages/recharge/recharge'
      },
      {
        icon: '/images/m_icon5.png',
        title: '关于天算',
        pathUrl: '/pages/about/about'
      },
      
    ]
  },
  goPath(e){
    util.check_login()
    let url = e.currentTarget.dataset.path;
    wx.navigateTo({
      url
    })
  },
  //去个人信息
  goPersonal(){
    util.check_login()
    wx.navigateTo({
      url: '/pages/personal/personal',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var token = getApp().globalData.token;
    console.log(token)
    var token = wx.getStorageSync('token')
    if(token){
      this.setData({sex:''})
    }else{
      this.setData({sex:'去登录'})
    }
    
    app.https_request(util.web_url.index,{id:123},'POST',false,false,this,getCurrentPages()).then( (res)=>{
      this.setData({'wechatNumber':res.data.csWeChat});
      this.setData({'kefu':app.globalData.domain+res.data.csqrcode});
      wx.setStorageSync('website', res.data.awebsite)
      wx.setStorageSync('mailbox', res.data.mailbox)
      wx.setStorageSync('csWeChat', res.data.csWeChat)
      wx.setStorageSync('csqrcode', res.data.csqrcode)
      wx.setStorageSync('agreement', res.data.agreement)
      wx.setStorageSync('privacy', res.data.privacy)
      }).catch( (errMsg)=>{});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    app.curl(util.web_url.my,{token:wx.getStorageSync('token')},'POST',false,false,this,getCurrentPages()).then( (res)=>{
      console.log(res.data)
      this.setData({phone:res.data.nickname,headImg:res.data.avatar})
      var add = {
        icon: '/images/down.png',
        title: '个人档案',
        pathUrl: '/pages/file/admin'
      }
      
      if(res.data.type == 2){
        this.data.myList[7] = add
        this.setData({myList:this.data.myList})
      }

  }).catch( (errMsg)=>{});
  },go_login(){
    util.check_login()
 
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})